<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日期类型</title>
    <script>
        function f1() {
            let date = new Date();
            console.log(date);
            console.log(date.getFullYear())
            console.log(date.getMonth())
            console.log(date.getDate())
            console.log(date.getHours())
            console.log(date.getMinutes())
            console.log(date.getSeconds())
            console.log(date.getDay())
            console.log(date.getTime())
            let date2 = new Date(date.getTime() - 24 * 60 * 60 * 1000)
        }

        function f2() {
            let date = new Date();
            console.log(date.getFullYear() + "年" + fn(date.getMonth() + 1) + "月" + fn(date.getDate()) + "日 " + fn(date.getHours()) + ":" + fn(date.getMinutes()) + ":" + fn(date.getSeconds()));
            date = new Date(date.getTime() - 24 * 60 * 60 * 1000)
            console.log(date.getFullYear() + "年" + fn(date.getMonth() + 1) + "月" + fn(date.getDate()) + "日 " + fn(date.getHours()) + ":" + fn(date.getMinutes()) + ":" + fn(date.getSeconds()));
            // 日期值的每个部分均支持运算
            date.setMonth(13);
            console.log(date.getFullYear() + "年" + fn(date.getMonth() + 1) + "月" + fn(date.getDate()) + "日 " + fn(date.getHours()) + ":" + fn(date.getMinutes()) + ":" + fn(date.getSeconds()));
        }

        function fn(s) {
            s = "0" + s;
            return s.substring(s.length - 2);
        }
    </script>
</head>
<body>
<button onclick="f1()">定义方式</button>
<br>
<button onclick="f2()">格式化日期</button>
<br>
</body>
</html>